package com.heima.behavior.controller;

import com.heima.behavior.dto.BehaviorDto;
import com.heima.behavior.service.IApLikesBehaviorService;
import com.heima.common.dto.ResponseResult;
import com.heima.common.dto.User;
import com.heima.common.dto.UserThreadLocalUtil;
import com.heima.common.enums.AppHttpCodeEnum;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * APP点赞行为表 前端控制器
 * </p>
 *
 * @author Wq
 * @since 2022-10-18
 */
@RestController
@RequestMapping("/api/v1/likes_behavior")
@Api(tags = "APP点赞行为表接口")
@CrossOrigin
public class ApLikesBehaviorController {

    @Autowired
    private IApLikesBehaviorService apLikesBehaviorService;

    /**
     * 保存文章点赞行为
     *
     * @param dto dto
     * @return {@link ResponseResult}
     */
    @PostMapping
    public ResponseResult saveApLikes(@RequestBody BehaviorDto dto) {
        //获取当前登录人
        User user = UserThreadLocalUtil.get();
        if (user == null || user.getUserId() == 0) {
            return ResponseResult.errorResult(AppHttpCodeEnum.NEED_LOGIN);
        }
        dto.setUserId(user.getUserId());
        return apLikesBehaviorService.saveApLikes(dto);
    }

}
